﻿using Cms.Core.Infrastructure.Extension;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Cms.Core.Infrastructure.Attributes;
using System.Reflection;

namespace Cms.Core.Infrastructure.Helps
{
   public  class EntityQueryFilter
    {

        /// <summary>
        /// 得到已过滤名字字符串
        /// </summary>
        /// <typeparam name="Entity"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static string GetAlreadyFilterNameString<Entity>() where Entity:class,new()
        {

            var type = typeof(Entity);
            var piInfo = type.GetProperties().Where(o => !o.HasAttribute<DisableSelectorAttribute>());
            if (!piInfo.Any())
            {
                return string.Empty;
            }
            string piName = piInfo.Select(pi => pi.Name).ToJoin(", ");
            piName = piName?.TrimEnd(' ');

            return $"new({piName})";

        }
    }
}
